<template>
	<view class="page">
		
		<!-- 订单商品 -->
		<view class="order-goods">
			<view class="goods-list">
				<view class="list" v-for="(item,index) in order" :key="index">
					<view class="thumb">
						<image :src="item.goods_cover" mode=""></image>
					</view>
					<view class="item">
						<view class="title">
							<text class="one-omit">{{item.goods_name}}</text>
						</view>
						<view class="num-size">
							<text>{{item.goods_spec}}</text>
						</view>
						<view class="price" style="display: flex;justify-content: space-between;">
							<text v-if="dataInfo.goods_type!=3">￥{{item.price_selling}}</text>
							<text v-if="dataInfo.goods_type==3">{{item.price_selling}} 礼品卡</text>
							<text> x{{item.stock_sales}}</text>
						</view>
						<!-- <view class="order-btn">
							<view class="btn" @click="onApplyAftersales">
								<text>申请售后</text>
							</view>
						</view> -->
					</view>
				</view>
			</view>
			<!-- <view class="contact">
				<text class="iconfont icon-kefu"></text>
				<text>联系客服</text>
			</view> -->
		</view>
		<!-- 订单信息 -->
		<view class="order-info">
			<view class="info-list">
				<view class="list">
					<view class="title">订单编号:</view>
					<view class="content">
						<text>{{dataInfo.order_no}}</text>
						<text class="btn" @click="copy(dataInfo.order_no)">复制</text>
					</view>
				</view>
				<view class="list">
					<view class="title">下单时间:</view>
					<view class="content">
						<text>{{dataInfo.create_at}}</text>
					</view>
				</view>
				<view class="list" style="height: auto;align-items: flex-start;padding: 20rpx 0 ;">
					<view class="title">退款原因:</view>
					<view class="content">
						<textarea v-model="content" name="" placeholder-style="color:#999" style="background: #f7f7f7;height: 200rpx;padding: 20rpx;font-size: 24rpx;" placeholder="请输入退款原因"></textarea>
					</view>
				</view>
				<view class="list" style="height: auto;align-items: flex-start;padding: 20rpx 0 ;">
					<view class="title" >退款凭证:</view>
					<view class="content" style="width: 540rpx;">
						<view class="flex flex-line">
							<image src="/static/up_img.png" mode="" @click="uploadpic"></image>
							<view class="imags" v-for="(item,index) in images" :key="index">
								<image :src="item" mode=""></image>
								<view class="close" @click="closeImg(index)">
									<tui-icon name="close" :size="24" color="#fff"></tui-icon>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<!-- 订单明细 -->
		
		<!-- 底部按钮 -->
		<view class="footer-btn " style="background: transparent;bottom: 40rpx;">
			
			<view class="btn " style="width: 100%;">
				<text class="action" style="width: 100%;text-align: center;line-height: 70rpx;" @click="tuikuan">确认退款</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				dataInfo:'',
				order:[],
				order_no:'',
				address:'',
				community_pid:'',
				content:'',
				images:[]
			};
		},
		onLoad(e) {
			this.order_no=e.order_no
		},
		onShow() {
			this.getInfo()
		},
		methods:{
			/**
			 * 售后点击
			 */
			copy(e){
				let that = this
				uni.setClipboardData({
					data: e,
					success: function () {
						that.tui.toast('复制成功')
					}
				});
			},
			closeImg(e){
				this.images.splice(e, 1)
			},
			uploadpic(){
				let that = this
				uni.chooseImage({
					count: 1,
					sizeType: ['original', 'compressed'],
					sourceType: ['album', 'camera'],
					success: res => {
						// that.headerimg = res.tempFilePaths[0];
						let tempFilePaths = res.tempFilePaths[0];
						that.tui.uploadFile("api.data/upload",tempFilePaths).then((res) => {
							if(res.code==1){
								that.images.push(res.data.url)
							}
						}).catch((res) => {})
					}
				});
			},
			tuikuan(){
				let that = this
				let data = ''
				that.images.map((item,index)=>{
					data = item+','+ data
				})
				that.tui.request("api.auth.order/sale", "post", {order_no: that.order_no,remark:that.content,image:data}, false, true, false).then((res) => {
					console.log(res)
					that.tui.toast(res.info)
					if (res.code == 1) {
						setTimeout(function(){
							uni.navigateBack()
						},1000)
					}
				}).catch((res) => {
					console.log(res)
				})
			},
			openLocation: function (value) {
				uni.openLocation({
					longitude: Number(value.longitude),
					latitude: Number(value.latitude),
					name: value.address_area,
					address: value.address
				})
			},
			onApplyAftersales(){
				uni.navigateTo({
					url: '/pages/AfterSaleType/AfterSaleType',
				})
			},
			getInfo() {
				let that = this
				that.tui.request("api.auth.order/orderDetail", "post", {order_no: that.order_no}, false, true, false).then((res) => {
					console.log(res)
					if (res.code == 1) {
						that.dataInfo = res.data.info
						that.order = res.data.info.order
						that.address =res.data.info.address
						that.community_pid = res.data.info.community_info
					}
			
				}).catch((res) => {
					console.log(res)
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	@import 'OrderDetails.scss';
	page{padding-top: 20rpx;}
	.order-info{
		.content{
			image{width: 160rpx;height: 160rpx;margin-right: 20rpx;margin-bottom: 20rpx;}
			.imags{position: relative;
				.close{position: absolute;top: 0rpx;right: 20rpx;}
			}
		}
	}
</style>
